﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

using Common.Logging;

using Spring.Context;
using Spring.Context.Support;
using Spring.Web.Mvc;

namespace BOSS.Web
{
    public class MvcApplication : HttpApplication
    {
        /// <summary>
        /// 日志器
        /// </summary>
        private static readonly ILog logger = LogManager.GetLogger(typeof(MvcApplication));

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            logger.Info(string.Empty);
            logger.Info(new string('=', 40));
            logger.Info("系统启动....");

            logger.Info("注册路由映射");
            RegisterRoutes(RouteTable.Routes);

            logger.Info("初始化 Spring.Net");
        }

        protected void Application_End()
        {
            logger.Info(new string('=', 40));
            logger.Info("系统关闭....");
            logger.Info(string.Empty);
        }

        /// <summary>
        /// 判断当前是否处于 DEBUG 模式
        /// </summary>
        /// <returns></returns>
        public bool IsDebug
        {
            get
            {
#if DEBUG
                return true;
#else
                return false;
#endif
            }
        }
    }
}